package xyz.xtt.exchange.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.exchange.service.IDetailService;
import xyz.xtt.exchange.vo.NftInterestDetailsVo;

@Slf4j
@RequestMapping("/api/exchange")
@RestController
public class DetailController {
	@Autowired
	private IDetailService iDetailService;

	/**
	 * 原 xyz.xtt.exchange.controller.InterestController.getNftDetailsById(String,
	 * String, HttpServletRequest)
	 * 
	 * @param uid
	 * @param goodsId
	 * @param req
	 * @return
	 */
	@Operation(summary = "获取藏品详情", description = "goodsId")
	@GetMapping("/nftDetails")
	public ApiResult<NftInterestDetailsVo> getNftDetailsById(@RequestHeader("uid") String uid,
			@RequestParam("goodsId") @Validated @NotBlank(message = "资产ID不能为空") String goodsId, 
			@RequestParam(value = "assetAccountId", required = false, defaultValue = "0") Long assetAccountId,
			HttpServletRequest req) {
		log.info("requestUri: /api/exchange/nft/nftDetails，requestParams: uid{},goodsId{}", uid, goodsId);
		NftInterestDetailsVo nftDetailsVo = iDetailService.getNftDetails(assetAccountId, goodsId, uid);
		if (nftDetailsVo == null) {
			return ApiResult.failure(1, "数据不存在");
		} else {
			return ApiResult.ok(nftDetailsVo);
		}
	}

}
